function newcoord=changecoord_4(s1, s2, s3, a1, a2, a3, a4)
  %Take a 4-D matrix A with s1=size(A,1), s2=size(A,2), s3=size(A,3),s4=size(A,4)
  %Consider
  %B=reshape(A, s1*s2*s3*s4,1);

  %Take the coordinates a1, a2, a3, a4
  %This function gives the position in B of A(a1,a2,a3,a4)
  newcoord = a1 + (a2-1 + (a3-1 + (a4-1) *s3)*s2)*s1; 
  
end